/*
 * The MIT License (MIT)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package multiswarm.examples;

import java.util.HashMap;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.multiswarmgdx.KazuAgent;
import com.multiswarmgdx.MultiAgentMenuScreen;
import com.multiswarmgdx.AssisiAgent;

import multiswarm.Agent;
import multiswarm.AgentTouch;
import multiswarm.Arena;

public class DefaultArena extends Arena {
	
	public boolean spawnRandomWalker = false;
	public boolean spawnFollower = false;
    public boolean spawnFireflies = false;
	public boolean spawnTouchable = false;
		
	public DefaultArena(Game game) {
		super(game);
	}
	
	@Override
	public void show() {
		super.show();
		
		if (spawnRandomWalker) {
			for (int i = 0; i < 100; i++) {
				Agent agent = new RandomWalkAgent(this);

				agent.setPosition(rand.nextFloat()*w,rand.nextFloat()*h);
				agent.setAngle((float) (rand.nextFloat()*Math.PI));
				
				stage.addActor(agent);
			}
		}
		
		if (spawnFollower) {
			for (int i = 0; i < 200; i++) {
				Agent agent = new FollowerAgent(this);

				agent.setPosition(rand.nextFloat()*w,rand.nextFloat()*h);
				agent.setAngle((float) (rand.nextFloat()*Math.PI));
				
				stage.addActor(agent);
			}
		}
		
		if (spawnFireflies) {
			for (int i = 0; i < 300; i++) {
				Agent agent = new FireflyAgent(this);

				agent.setPosition((w*1.5f)-rand.nextFloat()*w*2,(h*1.5f)-rand.nextFloat()*h*2);
				agent.setAngle((float) (rand.nextFloat()*Math.PI));
				
				stage.addActor(agent);
			}
		}
		
		if (spawnTouchable) {
			for (int i = 0; i < 100; i++) {
				Agent agent = new TouchableAgent(this);

				agent.setPosition(rand.nextFloat()*w,rand.nextFloat()*h);
				agent.setAngle((float) (rand.nextFloat()*Math.PI));
				
				stage.addActor(agent);
			}
		}
		
	}
	
	@Override
	public void hide() {
		Gdx.app.log("DefaultArena", "hide");
		dispose();
	}
	
	HashMap<String, KazuAgent> knoackAgents = new HashMap<String, KazuAgent>();
	
	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		super.touchDown(screenX, screenY, pointer, button);
		
		return false;
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		// TODO Auto-generated method stub
		super.touchUp(screenX, screenY, pointer, button);
				
		return false;
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		// TODO Auto-generated method stub
		super.touchDragged(screenX, screenY, pointer);
		
		return false;
	}
	
	
	@Override
	public boolean mouseMoved(int screenX, int screenY) {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public boolean keyTyped(char character) {
		super.keyTyped(character);
		if(Gdx.input.isKeyPressed(Input.Keys.M)) {
			if (game != null) {
				game.setScreen(new MultiAgentMenuScreen(game));
			}
		}
		return true;
	}

	@Override
	public boolean scrolled(int amount) {
		// TODO Auto-generated method stub
		
		camera.zoom += amount/64f;
		
		if (camera.zoom<0.2f) camera.zoom = 0.2f;
		
		camera.update();
		
		//Gdx.app.log("zoom ", "" + camera.zoom);
		
		stage.setCamera(camera);
		rayHandler.setCombinedMatrix(camera.combined);
		
		return false;
	}

}
